#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QQmlContext>
#include "avatarimageprovider.h"
#include "friendimageprovider.h"
#include "lobbyimageprovider.h"
#include "friendmodel.h"
#include "lobbymodel.h"
#include "gamehistorymodel.h"

AvatarImageProvider *g_aip = NULL;
FriendImageProvider *g_fip = NULL;
LobbyImageProvider *g_lip = NULL;

QQmlApplicationEngine *engine;
FriendModel *fm;
LobbyModel *g_lobby_model;
GameHistoryModel *g_game_history_model;

int main(int argc, char *argv[])
{
    QGuiApplication app(argc, argv);

    engine = new QQmlApplicationEngine();
    QObject::connect(
        engine,
        &QQmlApplicationEngine::objectCreationFailed,
        &app,
        []() { QCoreApplication::exit(-1); },
        Qt::QueuedConnection);
    g_aip = new AvatarImageProvider();
    engine->addImageProvider(QLatin1String("avatar"), g_aip);
    g_fip = new FriendImageProvider();
    engine->addImageProvider(QLatin1String("friend"), g_fip);
    g_lip = new LobbyImageProvider();
    engine->addImageProvider(QLatin1String("lobby"), g_lip);

    QQmlContext *context = engine->rootContext();
    const QStringList moduleList = {"Core", "GUI"};
    fm = new FriendModel();
    g_lobby_model = new LobbyModel();
    g_game_history_model = new GameHistoryModel();
    context->setContextProperty("friendsModel", 	QVariant::fromValue(fm));
    context->setContextProperty("lobbyModel", 		QVariant::fromValue(g_lobby_model));
    context->setContextProperty("gameHistoryModel", QVariant::fromValue(g_game_history_model));
    engine->loadFromModule("dota683lobby", "Main");

    return app.exec();
}
